package com.cino.controller;

import com.cino.domain.LoginInfo;
import com.cino.exception.ContentEmptyException;
import com.cino.exception.PasswordCertificateException;
import com.cino.service.LoginService;
import com.cino.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {


    @Autowired
    private LoginService loginService;


    @PostMapping("/login")
    public AjaxResult userLogin(@RequestBody LoginInfo loginInfo){
        try {
            AjaxResult result= loginService.login(loginInfo);
            return AjaxResult.success(result);
        } catch (ContentEmptyException e) {
            e.printStackTrace();
          return AjaxResult.failed(e.getMessage());
        } catch (PasswordCertificateException e) {
            e.printStackTrace();
            return AjaxResult.failed(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.failed("系统繁忙 请稍后再试！");
        }
    }

}
